<?php
namespace app\modules\frontend\models;

use Yii;
use yii\base\Model;

class NavSearch extends Nav
{

    public function rules()
    {
        return [
            ['app_id', 'integer', 'message' => 'app_id必须为数字，或数字字符串', 
                            'min'=>0, 'tooSmall' => 'app_id最小存储0', 
                            'max'=>18446744073709551615, 'tooBig' => 'app_id最大存储18446744073709551615'],
            ['parentid', 'integer', 'message' => 'parentid必须为数字，或数字字符串', 
                         'min'=>0, 'tooSmall' => 'parentid最小存储0', 
                         'max'=>65535, 'tooBig' => 'parentid最大存储65535'],
        ];
    }

    public function scenarios()
    {
        return Model::scenarios();
    }

    public function search($params)
    {
        $data['NavSearch'] = $params;
        // P($data);

        $query = Nav::find();

        if (!($this->load($data) && $this->validate())) {
            return false;
        }
        // P($this);

        if(isset($this->parentid)){
            $query -> andWhere([
                'parentid' => $this->parentid,
            ]);            
        }

        if(isset($this->app_id)){
            $query -> andWhere([
                'app_id' => $this->app_id,
            ]);            
        }



        // P($query);

        return $query;
    }

    
}